package com.hr.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hr.entity.AoaUser;
import com.hr.service.AoaUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * (AoaUser)表控制层
 *
 * @author makejava
 * @since 2022-06-09 08:55:27
 */
@RestController
@RequestMapping("aoaUser")
public class AoaUserController  {
    /**
     * 服务对象
     */
    @Autowired
    private AoaUserService aoaUserService;

    /**
     * 根据用户名查询出单个用户
     * @return
     */
    @GetMapping("/queryByUserName")
    public ResponseEntity<AoaUser> queryByUserName(
            String userName
    ){
        QueryWrapper<AoaUser> wrapper = new QueryWrapper<>();
        wrapper.eq("user_name",userName);
        //调用mybatis plus提供的service方法
        AoaUser user = aoaUserService.getOne(wrapper);
        return ResponseEntity.ok(user);
    }

    /**
     * 分页查询和模糊查询
     * @param page
     * @param deptName
     * @return
     */
    @RequestMapping("/queryList")
    public Page<AoaUser> queryList(Page<AoaUser> page,String deptName){
        page=aoaUserService.queryList(page,deptName);
        return page;
    }

    /**
     * 保存或修改
     * @param aoaUser
     * @return
     */
    @PostMapping("/save")
    public boolean save(@RequestBody AoaUser aoaUser) {
        return aoaUserService.save(aoaUser);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public boolean delete(Integer id) {
        return aoaUserService.delete(id);
    }

    /**
     * 单值查询
     * @param id
     * @return
     */
    @GetMapping("/queryById")
    public AoaUser queryById(Integer id) {
        return aoaUserService.queryById(id);
    }
}

